<?php /*

*/
session_start();
error_reporting(E_ALL ^ E_NOTICE);
$connect = mysql_connect('localhost','root','');
mysql_select_db("ajaxadmintool");

?>
<form action="login.php" method="post">
<input type="text" value="<?php echo $_POST['username'];?>" name="username" />
<input type="password" value="<?php echo $_POST['password'];?>" name="password" />
<select type="option" name="role">
<option value="admin">Admin</option>
<option value="pm">Project Manager</option>
<option value="tl">Team Leader</option>
<option value="trainee">Trainee</option>
</select>
<input type="submit" value="login" name="submit" />
</form>

<?php 
if($_SESSION["loggedin"]==true)
{
if($_SESSION[role]=="admin")
{
$_SESSION[msg]="Register in admin section";
header("Location: admin.php");
}
elseif($_SESSION[role]=="pm")
{
header("Location: pm.php");
}
elseif($_SESSION[role]=="tl")
{
header("Location: tl.php");
}
elseif($_SESSION[role]=="trainee")
{
header("Location: trainee.php");
}
}
?>




<?php
if(isset($_POST['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$role = $_POST['role'];

$select = "SELECT role from login WHERE username='$username' and password='$password' and role='$role'";
$result = mysql_query($select);
$row =mysql_fetch_array($result);
//echo $row[role];
if(empty($row))
{
echo 'invalid';
}
else{
$_SESSION["loggedin"]=true;
if($row[role]=="admin")
{
$_SESSION["role"] =admin;
header("Location: admin.php");
}
elseif($row[role]=="pm")
{
$_SESSION["role"] =pm;
header("Location: pm.php");
}
elseif($row[role]=="tl")
{
$_SESSION["role"] =tl;
header("Location: tl.php");
}
elseif($row[role]=="trainee")
{
$_SESSION["role"] =trainee;
header("Location: trainee.php");
}
}

//print_r($row);
}

 
 ?>